home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / libguile / files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-13  |  4.0 KB  |  175 lines

  1. /*    Copyright (C) 1995 Free Software Foundation, Inc.
  2.  * 
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2, or (at your option)
  6.  * any later version.
  7.  * 
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  * GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this software; see the file COPYING.  If not, write to
  15.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  *
  17.  * As a special exception, the Free Software Foundation gives permission
  18.  * for additional uses of the text contained in its release of GUILE.
  19.  *
  20.  * The exception is that, if you link the GUILE library with other files
  21.  * to produce an executable, this does not by itself cause the
  22.  * resulting executable to be covered by the GNU General Public License.
  23.  * Your use of that executable is in no way restricted on account of
  24.  * linking the GUILE library code into it.
  25.  *
  26.  * This exception does not however invalidate any other reasons why
  27.  * the executable file might be covered by the GNU General Public License.
  28.  *
  29.  * This exception applies only to the code released by the
  30.  * Free Software Foundation under the name GUILE.  If you copy
  31.  * code from other Free Software Foundation releases into a copy of
  32.  * GUILE, as the General Public License permits, the exception does
  33.  * not apply to the code that you add in this way.  To avoid misleading
  34.  * anyone as to the status of such modified files, you must delete
  35.  * this exception notice from them.
  36.  *
  37.  * If you write modifications of your own for GUILE, it is your choice
  38.  * whether to permit this exception to apply to your modifications.
  39.  * If you do not wish that, delete this exception notice.  
  40.  */
  41.  
  42.  
  43.  
  44. #include <stdio.h>
  45. #include "_scm.h"
  46.  
  47.  
  48.  
  49. /* {Files in general}
  50.  */
  51.  
  52.  
  53. #if (__TURBOC__==1)
  54. #undef L_tmpnam        /* Not supported in TURBOC V1.0 */
  55. #endif
  56. #ifdef GO32
  57. #undef L_tmpnam
  58. #endif
  59. #ifdef MWC
  60. #undef L_tmpnam
  61. #endif
  62.  
  63. #ifdef L_tmpnam
  64.  
  65.  
  66. PROC (s_tmpnam, "tmpnam", 0, 0, 0, scm_tmpnam);
  67. #ifdef __STDC__
  68. SCM 
  69. scm_tmpnam (void)
  70. #else
  71. SCM 
  72. scm_tmpnam ()
  73. #endif
  74. {
  75.   char name[L_tmpnam];
  76.   SYSCALL (tmpnam (name););
  77.   return scm_makfromstr (name, strlen (name), 0);
  78. }
  79.  
  80. #else
  81. /* TEMPTEMPLATE is used only if mktemp() is being used instead of
  82.    tmpnam(). */
  83.  
  84. #ifdef AMIGA
  85. #define TEMPTEMPLATE "T:SchemeaaaXXXXXX";
  86. #else
  87. #ifdef vms
  88. #define TEMPTEMPLATE "sys$scratch:aaaXXXXXX";
  89. #else /* vms */
  90. #ifdef __MSDOS__
  91. #ifdef GO32
  92. #define TEMPTEMPLATE "\\tmp\\TMPaaaXXXXXX";
  93. #else
  94. #define TEMPTEMPLATE "TMPaaaXXXXXX";
  95. #endif
  96. #else /* __MSDOS__ */
  97. #define TEMPTEMPLATE "/tmp/aaaXXXXXX";
  98. #endif /* __MSDOS__ */
  99. #endif /* vms */
  100. #endif /* AMIGA */
  101.  
  102. char template[] = TEMPTEMPLATE;
  103. #define TEMPLEN (sizeof template/sizeof(char) - 1)
  104. PROC (s_tmpnam, "tmpnam", 0, 0, 0, scm_tmpnam);
  105. #ifdef __STDC__
  106. SCM 
  107. scm_tmpnam (void)
  108. #else
  109. SCM 
  110. scm_tmpnam ()
  111. #endif
  112. {
  113.   SCM name;
  114.   int temppos = TEMPLEN - 9;
  115.   name = scm_makfromstr (template, (sizet) TEMPLEN, 0);
  116.   DEFER_INTS;
  117. inclp:
  118.   template[temppos]++;
  119.   if (!isalpha (template[temppos]))
  120.     {
  121.       template[temppos++] = 'a';
  122.       goto inclp;
  123.     }
  124. #ifndef AMIGA
  125. #ifndef __MSDOS__
  126.   SYSCALL (temppos = !*mktemp (CHARS (name)););
  127.   if (temppos)
  128.     name = BOOL_F;
  129. #endif
  130. #endif
  131.   ALLOW_INTS;
  132.   return name;
  133. }
  134.  
  135. #endif /* L_tmpnam */
  136.  
  137.  
  138. #ifdef M_SYSV
  139. #define remove unlink
  140. #endif
  141.  
  142. PROC (s_sys_delete_file, "%delete-file", 1, 0, 0, scm_sys_delete_file);
  143. #ifdef __STDC__
  144. SCM 
  145. scm_sys_delete_file (SCM str)
  146. #else
  147. SCM 
  148. scm_sys_delete_file (str)
  149.      SCM str;
  150. #endif
  151. {
  152.   int ans;
  153.   ASSERT (NIMP (str) && STRINGP (str), str, ARG1, s_sys_delete_file);
  154. #ifdef STDC_HEADERS
  155.   SYSCALL (ans = remove (CHARS (str)));
  156. #else
  157.   SYSCALL (ans = unlink (CHARS (str)));
  158. #endif
  159.   return ans ? BOOL_F : BOOL_T;
  160. }
  161.  
  162.  
  163.  
  164. #ifdef __STDC__
  165. void
  166. scm_init_files (void)
  167. #else
  168. void
  169. scm_init_files ()
  170. #endif
  171. {
  172. #include "files.x"
  173. }
  174.  
  175.